Load Libraries
library(tidyverse)
## ── Attaching packages ─────────────────────────────────────── tidyverse 1.3.1 ──
## ✓ ggplot2 3.3.5 ✓ purrr 0.3.4
## ✓ tibble 3.1.4 ✓ dplyr 1.0.7
## ✓ tidyr 1.1.3 ✓ stringr 1.4.0
## ✓ readr 2.0.1 ✓ forcats 0.5.1
## ── Conflicts ────────────────────────────────────────── tidyverse_conflicts() ──
## x dplyr::filter() masks stats::filter()
## x dplyr::lag() masks stats::lag()
library(RColorBrewer)
library(plotly)
##
## Attaching package: 'plotly'
## The following object is masked from 'package:ggplot2':
##
## last_plot
## The following object is masked from 'package:stats':
##
## filter
## The following object is masked from 'package:graphics':
##
## layout
Read Data
sharks <- read_csv(file="./data/SharksClean.csv")
## Rows: 23 Columns: 5
## ── Column specification ────────────────────────────────────────────────────────
## Delimiter: ","
## chr (3): Genus, Species, Sex
## dbl (2): BodySize, ToothSize
##
## ℹ Use `spec()` to retrieve the full column specification for this data.
## ℹ Specify the column types or set `show_col_types = FALSE` to quiet this message.
dim(sharks)
## [1] 23 5
Interactive Scatterplot
mycols <- brewer.pal(4, 'Dark2')
plot_ly(data=sharks,
type='scatter',
mode='markers',
x = ~ToothSize,
y = ~BodySize,
color = ~Genus,
colors = mycols,
opacity = 0.7,
marker = list(size = 11),
text = paste0('Genus: ', sharks$Genus, '<br>',
'Species: ', sharks$Species, '<br>',
'Tooth Size: ', sharks$ToothSize, '<br>',
'Body Size: ', sharks$BodySize, '<br>'),
hoverinfo = 'text') %>%
layout(title = list(text = "Sharks: Body size vs. Tooth Size"),
xaxis = list(title = "Tooth Size", zeroline = FALSE),
yaxis = list(title = "Body Size"),
legend = list(title = list(text = 'Genus'))) %>%
config(displayModeBar = F)